package com.lb.activity.rest;


import com.lb.activity.annotation.RequestLimit;
import com.lb.activity.po.WebArticleComment;
import com.lb.activity.service.TextService;
import com.lb.activity.util.ResultUtil;
import com.lb.activity.vo.ArticleVo;
import feign.Headers;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
public class IndexController {

    /**
     * 注入服务层接口
     */
    @Resource
    private TextService testService;


    /**
     * 通过Feign客户端的方式，调用之前一个服务的API
     *
     * @return
     */
    @RequestMapping("/rest/texts")
    public Map<String, Object> texts(Integer page) {
        Map<String, Object> map = testService.restTexts(page);
        return map;
    }


    @GetMapping("show/{id}")
    public ArticleVo showData(@PathVariable("id")Long id){
        ArticleVo webArticle = testService.showData(id);
        return webArticle;
    }

    @GetMapping("sync/data")
    public void syncInfo(){
        testService.syncData();
    }

    @GetMapping("webArticles")
    public List<ArticleVo> webArticles(){
        List<ArticleVo> articleVos = testService.arts();
        return articleVos;
    }
    @PostMapping("addComment")
    public Object addComment(@RequestBody WebArticleComment webArticleComment){
        ResultUtil resultUtil = testService.addComment(webArticleComment);
        return resultUtil;
    }

    @PostMapping("comments")
    public Object comments(@RequestParam("actId") Long actId){
        ResultUtil resultUtil = testService.comments(actId);
        return resultUtil;
    }

    @PostMapping("hotCommentAct")
    public Object hotCommentAct(){
        ResultUtil resultUtil = testService.hotCommentAct();
        return resultUtil;
    }


}
